import pika
import sys
import random

# work queue ( task queue )
# https: // www.rabbitmq.com / tutorials / tutorial - two - python.html

auth = pika.PlainCredentials('test', 'test')
connection = pika.BlockingConnection(
    pika.ConnectionParameters('hadoop888', credentials=auth))
channel = connection.channel()
channel.queue_declare(queue='task_queue', durable=True)  # make queue durable

message = ' '.join(sys.argv[1:]) or "Hello World!" + '.' * random.randrange(5)
channel.basic_publish(exchange='',
                      routing_key='task_queue',
                      body=message,
                      properties=pika.BasicProperties(
                          delivery_mode=2,  # make message persistent
                      ))
print(" [x] Sent %r" % message)
connection.close()
